var $ = require('jquery');
var validator = module.exports = require('jquery-validation');

require('jquery-validation/localization/messages_zh');

$.validator.setDefaults({
    ignore: 'input[type=hidden]:not(.form-item)',
    highlight: function(element) {
        var tabcontent = $(element).closest('.tab-pane');

        if (tabcontent.not('.active')) {
            $('a[href="#' + tabcontent.attr('id') + '"]').tab('show');
        }

        $(element).closest('.form-group').addClass('has-error');
    },
    unhighlight: function(element) {
        $(element).closest('.form-group').removeClass('has-error');
    },
    errorElement: 'p',
    errorClass: 'error',
    errorPlacement: function(error, element) {
        if($(element).hasClass('timetext')){
            error.appendTo(element.parents("div.col-xs-6").nextAll("div:last"));
        }else if(element.name = 'roleIds'){
            error.appendTo(element.parents("div.col-xs-6").next('.col-xs-4'));
        }else {
            $(element).parent().next('div.col-xs-4').append(error);
        }
    }
});
//包含特殊字符
jQuery.validator.addMethod('hasSpecial',function (value,element) {
    value = $.trim(value)
    var tel = /((?=[\x21-\x7e]+)[^A-Za-z0-9])/;
    var sp = /\s/
    return  (!tel.test(value))&&!sp.test(value);
},"该字段不能有特殊字符和空格");